/* File makes Table 12 */

/* 	Input files: 	fw_combinatorics
	Output files: T12_Combinatorics.tex */

**********************************************
clear all
macro drop _all
scalar drive		= "E:"
scalar maindir		= "`=drive'\Replicate"
scalar tabledir		= "`=drive'\Replicate\TablesRep"
cd "`=maindir'"
**********************************************

use fw_combinatorics, clear  

drop sheepid symbolid2 
ren userid2 userid
ren num_all num_sent
ren num_bull_all num_sent_bull
ren num_bull num_rec_bull
ren num_chosen num_rec
ren bear2 bear
ren bull2 bull
gen all_same=cond(all_bull==1 | all_bear==1,1,0)
order date symbolid userid

foreach xx in all_same all_bull all_bear {
replace `xx'=`xx'*100
}

**********************************************


qui reghdfe all_bull prob_bull_same bull, absorb( i.userid i.symbolid#i.date) 
keep if e(sample)==1

eststo P_0: reghdfe all_bull prob_bull_same, noabsorb vce(cl userid)
	qui sum all_bull if e(sample)==1
	qui estadd scalar avg = r(mean)
	qui estadd local daysymbolFE "-"
	qui estadd local userFE "-" 
eststo P_1: reghdfe all_bull prob_bull_same bull, absorb( i.userid) vce(cl userid)
	qui sum all_bull if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100
	qui estadd local daysymbolFE "-"
	qui estadd local userFE "Y" 
eststo P_2: reghdfe all_bull prob_bull_same bull, absorb( i.userid i.symbolid#i.date) vce(cl userid)
	qui sum all_bull if e(sample)==1
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100
	qui estadd scalar avg = r(mean)
	qui estadd local daysymbolFE "Y"
	qui estadd local userFE "Y"
	
eststo P_3: reghdfe all_bear prob_bear_same, noabsorb  vce(cl userid)
	qui sum all_bear if e(sample)==1
	qui estadd scalar avg = r(mean)
	qui estadd local daysymbolFE "-"
	qui estadd local userFE "-"
eststo P_4: reghdfe all_bear prob_bear_same bear, absorb( i.userid) vce(cl userid)
	qui sum all_bear if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bear]/avg)*100
	qui estadd local daysymbolFE "-"
	qui estadd local userFE "Y"
eststo P_5: reghdfe all_bear prob_bear_same bear, absorb( i.userid i.symbolid#i.date ) vce(cl userid)
	qui sum all_bear if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bear]/avg)*100
	qui estadd local daysymbolFE "Y"
	qui estadd local userFE "Y"

********************************************

local stats_opts " stats(N N_clust r2 avg effect_size userFE daysymbolFE, fmt(%18.0fc %18.0fc %12.2fc %12.1fc %12.0fc) labels("\# obs." "\# clusters (users)" "$\textit{R}^2$" "Mean of dependent var.(\%)" "Main effect size (\% of mean)" "User FE" "Day x Symbol FE") ) " 

#delimit ; 
local opts   "b(%16.2fc) se(%16.2fc) brackets booktabs  star(* 0.10 ** 0.05 *** 0.01) nonotes lines 
mtitles("Bullish" "Bullish" "Bullish" "Bearish" "Bearish" "Bearish" )
mgroups("Dep. var.: $\mathbbm{1}$ x 100 if all messages received on day t have sentiment that is"
, pattern(1 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  " ;     

cd "`=tabledir'" ;
esttab P* using T12_combinatorics.tex, `opts' `stats_opts'  
drop(_cons) order(prob_bull_same prob_bear_same) coef(
bull "$\mathbbm{1}$ Declare Bull\textsubscript{i,s,t-7 to t-1}" 
bear "$\mathbbm{1}$ Declare Bear\textsubscript{i,s,t-7 to t-1}" 
prob_bear_same "Expected Pr(all Bear) if random\textsubscript{i,s,t}" 
prob_bull_same "Expected Pr(all Bull) if random\textsubscript{i,s,t}")  replace ; 
#delimit cr 
cd "`=maindir'"


